package com.haixee.parkdemo.log.service.impl;

import com.haixee.parkdemo.common.context.WebContextHolder;
import com.haixee.parkdemo.log.dao.LogCustomMapper;
import com.haixee.parkdemo.log.dao.LogMapper;
import com.haixee.parkdemo.log.feign.AuthService;
import com.haixee.parkdemo.log.model.Log;
import com.haixee.parkdemo.log.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LogServiceImpl implements LogService {

    @Autowired
    private LogMapper logMapper;

    @Autowired
    private LogCustomMapper logCustomMapper;

    @Autowired
    private AuthService authService;

    @Override
    public void writeLog(Integer uid, String content) {
        Log log = new Log();
        log.setContent(content);
        log.setOptId(uid);
        log.setOptJob(WebContextHolder.getJobId());
        logMapper.insertSelective(log);
    }

    @Override
    public List<Log> getList(Integer uid) {

        // 上级项目id
//        Integer[] jobIdList =  WebContextHolder.getJobList();
        List<Integer> underJobList = authService.getGroupTree(uid);

        return logCustomMapper.selectByOptIdOrOptJobIn(uid, underJobList);
    }
}
